<template>
	<u-no-network></u-no-network>
	<view class="sun-index">
		<view class="sun-login-box" style="margin-top: 30rpx;">
			<view class="sun-label">
				<image style="width: 28rpx;height:39rpx;" src="@/static/imgs/mobile_icon.png" />
				<text class="label-text">账号</text>
			</view>
			<view class="sun-input-box">
				<input v-model="uid" type="text" placeholder="请输入账号" placeholder-class="placeholder-class" />
				<image @click="uid=''" class="close-icon" src="@/static/imgs/close_icon.png" />
			</view>
		</view>
		<view class="sun-login-box">
			<view class="sun-label">
				<image style="width: 28rpx;height:39rpx;" src="@/static/imgs/nickname.png" />
				<text class="label-text">姓名</text>
			</view>
			<view class="sun-input-box">
				<input v-model="uname" type="text" placeholder="请输入姓名" placeholder-class="placeholder-class" />
				<image @click="uname=''" class="close-icon" src="@/static/imgs/close_icon.png" />
			</view>
		</view>
		<view class="sun-login-box">
			<view class="sun-label">
				<image style="width: 29rpx;height:37rpx;" src="@/static/imgs/pwd_icon.png" />
				<text class="label-text">密码</text>
			</view>
			<view class="sun-input-box">
				<input v-model="pwd" type="password" placeholder="请输入密码" placeholder-class="placeholder-class" />
				<image @click="pwd=''" class="close-icon" src="@/static/imgs/close_icon.png" />
			</view>
		</view>
		<view class="sun-login-box">
			<view class="sun-label">
				<image style="width: 29rpx;height:37rpx;" src="@/static/imgs/pwd_icon.png" />
				<text class="label-text">确认密码</text>
			</view>
			<view class="sun-input-box">
				<input v-model="pwdAgain" type="password" placeholder="请输入密码" placeholder-class="placeholder-class" />
				<image @click="pwdAgain=''" class="close-icon" src="@/static/imgs/close_icon.png" />
			</view>
		</view>

		<view class="login-btn-box">
			<view class="login-btn" @click="cancel" style="background-color: skyblue;">取消</view>
		</view>
		<view class="register-btn-box">
			<view class="login-btn" @click="registerUser" style="background-color: #12C8B9;">确认</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uname: '',
				uid: '',
				pwd: '',
				pwdAgain: '',
				show: false,
				customLst: [{
					code: 1,
					text: '优泰科技'
				}, {
					code: 2,
					text: '三德科技'
				}]
			}
		},
		onShow() {

		},
		onLoad: function(option) {

		},
		methods: {
			cancel() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			registerUser() {
				if(!this.uid||!this.uname||!this.pwd||!this.pwdAgain){
					this.$u.toast('请输入注册信息');
					return;
				}
				if(this.pwd!=this.pwdAgain){
					this.$u.toast('二次密码不一致');
					return;
				}
				this.$request('User/ExistUserAsync','GET',{
					"userCode":this.uid
				}).then(res=>{
					if(res.data)
					{
						this.$u.toast(`已存在账户${this.uid}`);
						return;
					}
				});
				this.$request('User/RegisterUserAsync', 'POST', {
					"userCode": this.uid,
					"userName": this.uname,
					"userPwd": this.pwd
				}).then(res => {
					console.log(res)
					if (res.data) {
						this.$u.toast("注册成功");
						uni.navigateTo({
							url: '/pages/login/login'
						})
					} else {
						this.$u.toast("服务器发送错误，请联系管理员");
					}
					this.showLoading = false;
				})
			},
			actionSheetCallback(index) {
				var item = this.customLst[index];
				this.customId = item.code;
				this.custom = item.text;
			}
		}
	}
</script>

<style>
	@import url("login.css");
</style>